home *** CD-ROM | disk | FTP | other *** search
- /*
- *-----------------------------------------------------------------------------
- * toascii - Strip a file of all chars that are not printable
- * except CRLF. Expands tabs.
- *-----------------------------------------------------------------------------
- *
- * (c) Copyright 1986 by Daniel C. Brotherton All Rights Reserved
- *
- * May be used for any personal, nonprofit purpose. Commercial users or
- * anyone with questions/comments may contact me at:
- * GEnie D.BROTHERTON
- * Delphi LOBODAN
- * CIS 74746,3307
- *
- * Written using Alcyon C v. 4.14 (updated version from Atari)
- *
- *-----------------------------------------------------------------------------
- */
-
- #include <stdio.h>
- #include <ctype.h>
-
- #define DEFTABS 8L
-
- long tabval = DEFTABS;
-
- main(argc, argv)
-
- int argc;
- char *argv[];
-
- {
- long count, /* char # in line */
- to_tab; /* spaces to next tab */
- char c; /* input holder */
-
- parse(argc, argv);
-
- while((c = getchar()) != EOF){
- if (isprint(c)){ /* if printable, print */
- putchar(c);
- count++; /* and add to total */
- }else if (c == '\n'){ /* if CRLF put it out */
- putchar('\n');
- count = 0L; /* reset char counter */
- }else if (c == '\t'){ /* if tab, expand it */
- to_tab = tabval - (count % tabval);
- spaces((int)to_tab);
- count += to_tab;
- }else{ /* replace with blank */
- putchar(' ');
- count++; /* and add to total */
- }
- }
- out();
- }
-
-
-
- /*
- *---------------------------------------------------------------------------
- * Parse input and set control values
- *---------------------------------------------------------------------------
- */
- static VOID parse(argc, argv)
-
- #define MINTAB 01
- #define MAXTAB 80
-
- int argc;
- char *argv[];
-
- {
-
- int i;
-
- if (argc < 1)
- return; /* no options selected */
-
- for (i = 1; i < argc; ++i) { /* parse out switches */
- if (argv[i][0] != '-')
- parse_er(argv[i]);
-
- switch (toupper(argv[i][1])) {
- case 'T': /* Set tab value */
- tabval = atol(&argv[i][2]);
- if ((tabval < MINTAB) || (tabval > MAXTAB))
- parse_er(argv[i]);
- break;
- default: /* Invalid entry */
- parse_er(argv[i]);
- break;
- }
- }
- }
-
-
-
- /*
- *---------------------------------------------------------------------------
- * Output error messages
- *---------------------------------------------------------------------------
- */
- static VOID parse_er(err_strg)
-
- char *err_strg;
-
- {
- puts("ERROR: invalid entry");
- spaces(4);
- puts(err_strg);
- puts("Usage: toascii [-T#]");
- puts(" -T = set tab value (default: 08)");
- out();
- }
-
-
-
- /*
- *---------------------------------------------------------------------------
- * Program exit - call to here never returns
- *---------------------------------------------------------------------------
- */
- static VOID out()
- {
- exit(0);
- }
-
-
-
- /*
- *---------------------------------------------------------------------------
- * Output specified number of spaces
- *---------------------------------------------------------------------------
- */
- static VOID spaces(i)
-
- int i;
-
- {
- int j;
-
- for (j = 0; j < i; ++j)
- putchar(' ');
- }
- əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə